import { Component, Injector } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { PIC_URL } from "../../../../providers/Config";
import { StorageService } from '../../../../providers/StorageService';
import { BasePage } from '../../../../pages/basePage';
import { UserService } from '../../../../providers/UserService';

/**
 * Generated class for the BoughtNailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-bought-nail',
  templateUrl: 'bought-nail.html',
})
export class BoughtNailPage extends BasePage{
  picrooturl = "";//图片服务地址
  userinfo = {}//获取内存中的数据
  pop=1;
  boughtList=[];  //获取的已买款式订单列表
  bottom1:boolean=false;
  constructor(injector: Injector,public stc: StorageService,public UserService:UserService) {
    super(injector);
    this.picrooturl = PIC_URL;
    this.userinfo = this.stc.read('userinfo');
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad BoughtNailPage');
    this.getboughtNial('');
  }
  async getboughtNial(infiniteScroll){
    let param={shop_id:this.userinfo['shop_id'],type_id:1,pop:this.pop};
    let result=await this.UserService.shopOrderAPI(param);
    console.log(result);
    if(result.code == 1){
      this.pop++;
      this.boughtList= this.boughtList.concat(result.data);
      if(infiniteScroll){
        this.bottom1=false;
        infiniteScroll.complete(); //请求完成数据更新页面
        if (result.data.length < 6) {
			    infiniteScroll.enable(false);
          this.bottom1 = true;
        }
      }
    }else{
      let toast = this.toastCtrl.create({
        message: result.msg,
        duration: 2000,
        position: 'bottom',
      })
      toast.present();
    }
  }

  //无限滚动
  doInfinite(infiniteScroll) {
    this.bottom1 = false;
    this.getboughtNial(infiniteScroll);
  }
}
